package net.easyjava.third.rongcloud.rong.models.message;

import com.alibaba.fastjson.JSONObject;
import net.easyjava.third.rongcloud.rong.constants.RongCloudConstants;
import net.easyjava.third.rongcloud.rong.models.ImgMessage;
import net.easyjava.third.rongcloud.rong.models.TxtMessage;
import net.easyjava.tools.BaseBean;
import net.easyjava.tools.lang.StringTools;


/**
 * 接收到的消息
 * Created by wxnacy on 16/3/8.
 */
public class ReceiveMessage extends BaseBean {
    private static final long serialVersionUID = 3120882126772976155L;
    private String fromUserId;
    private String toUserId;
    private String objectName;
    private String content;
    private String channelType;
    private String msgUID;
    private long timestamp;

    public ReceiveMessage() {
    }

    public boolean isChatroom(){
        return "".equals(this.channelType);
    }

    public boolean isTxtMessage(){
        return RongCloudConstants.OBJECT_NAME_TXT.equals(this.objectName);
    }
    public boolean isImgMessage(){
        return RongCloudConstants.OBJECT_NAME_IMG.equals(this.objectName);
    }

    /**
     * 获取图片消息
     * @return
     */
    public TxtMessage getTxtMessage(){
        if(StringTools.isEmpty(this.content)){
            return null;
        }
        content = content.replace("\\\"","\"");
        content = content.replace("\\\"","\"");
        return JSONObject.parseObject(this.content, TxtMessage.class);
    }

    public ImgMessage getImgMessage(){
        if(StringTools.isEmpty(this.content)){
            return null;
        }
        return JSONObject.parseObject(this.content,ImgMessage.class);
    }


    public String getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(String fromUserId) {
        this.fromUserId = fromUserId;
    }

    public String getToUserId() {
        return toUserId;
    }

    public void setToUserId(String toUserId) {
        this.toUserId = toUserId;
    }

    public String getObjectName() {
        return objectName;
    }

    public void setObjectName(String objectName) {
        this.objectName = objectName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getChannelType() {
        return channelType;
    }

    public void setChannelType(String channelType) {
        this.channelType = channelType;
    }

    public String getMsgUID() {
        return msgUID;
    }

    public void setMsgUID(String msgUID) {
        this.msgUID = msgUID;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
}
